Skip to content

fix(babel-preset): preserve Platform.select initializers - #58350

Closed
mfkrause wants to merge 1 commit into
react:mainfrom
mfkrause:fix/platform-select-side-effects
Closed

fix(babel-preset): preserve Platform.select initializers#58350
mfkrause wants to merge 1 commit into
react:mainfrom
mfkrause:fix/platform-select-side-effects

Conversation

@mfkrause

@mfkrause mfkrause commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary:

The React Native Babel preset replaces Platform.select({...}) with the selected property during production transforms. JavaScript evaluates every object property initializer before calling Platform.select, so this can silently remove side effects from non-selected properties.

For example:

Platform.select({
  ios: selected(),
  android: discarded(),
});

JavaScript would run both side effects, selected() and discarded(). The plugin's current behavior removes discarded on iOS however.

This fix preserves both side effects by testing for purity.

Changelog:

[GENERAL] [FIXED] - Preserve side effects from discarded Platform.select property initializers in the Babel preset.

Test Plan:

Added a regression test and ran existing tests, linter and formatter.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 4, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 4, 2026
@meta-codesync

meta-codesync Bot commented Sep 7, 2026

Copy link
Copy Markdown

@vzaidman has imported this pull request. If you are a Meta employee, you can view this in D119065685.

@meta-codesync meta-codesync Bot closed this in f654cad Sep 9, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Sep 9, 2026
@meta-codesync

meta-codesync Bot commented Sep 9, 2026

Copy link
Copy Markdown

@vzaidman merged this pull request in f654cad.

@facebook-github-tools

Copy link
Copy Markdown

This pull request has been reverted by 679a7b7.

shashikant-panchal pushed a commit to shashikant-panchal/react-native that referenced this pull request Sep 10, 2026
Summary:
The React Native Babel preset replaces `Platform.select({...})` with the selected property during production transforms. JavaScript evaluates every object property initializer before calling `Platform.select`, so this can silently remove side effects from non-selected properties.

For example:

```js
Platform.select({
  ios: selected(),
  android: discarded(),
});
```

JavaScript would run both side effects, `selected()` and `discarded()`. The plugin's current behavior removes `discarded` on iOS however.

This fix preserves both side effects by testing for purity.

## Changelog:

[GENERAL] [FIXED] - Preserve side effects from discarded Platform.select property initializers in the Babel preset.

Pull Request resolved: react#58350

Test Plan: Added a regression test and ran existing tests, linter and formatter.

Reviewed By: GijsWeterings

Differential Revision: D119065685

Pulled By: vzaidman

fbshipit-source-id: ca209fe9b728990019e9da478670cc3bdb4cd6e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Reverted Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant